package cn._2dland.bots;

import cn._2dland.bots.servlets.BotAgent;

import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;

/**
 * 任务管理器
 */
public class TaskManager {
	private TaskManager() {}

	/**
	 * 创建任务
	 * @param action - 任务动作
	 * @param accountID - 帐号ID
	 */
	public static void createTask(Long accountID, int action) {
		String queueName = "default";
		switch(action){
		case BotAgent.ACTION_PICK:
			queueName = "pick-queue";
			break;
		case BotAgent.ACTION_RENEW:
			queueName = "daily-queue";
			break;
		}
		TaskOptions t = TaskOptions.Builder.withUrl("/bots/agent");
		t.method(TaskOptions.Method.POST);
		t.param("accountID", accountID.toString());
		t.param("action", String.valueOf(action));
		QueueFactory.getQueue(queueName).add(t);
	}
}